package com.java.digitalsignagesystem.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java.digitalsignagesystem.service.ApiService;
import org.springframework.stereotype.Service;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

@Service
public class ApiServiceImpl implements ApiService {
    @Override
    public void save() throws IOException {
        String path = "http://127.0.0.1:8083/savehttp/doGetControllerOne";
        BufferedReader in = null;
        StringBuffer result = null;
        URL url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.connect();
        result = new StringBuffer();
        //读取url的响应
        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
            result.append(line);
        }
        JSONArray jsonArray = JSON.parseArray(String.valueOf(result));
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i); //获取
           //处理数据
        }

    }
}

